package com.blog.controller.login;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.blog.entity.User;
import com.blog.services.loginModel.LoginImplService;

@Controller
@RequestMapping(value = "/user/login")
public class LoginController {
	private final Logger log = Logger.getLogger(getClass());
	@Resource
	private User user;
	
	@Resource
	private LoginImplService loginService;

	@RequestMapping(value = "/xx")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response, HttpSession session)
			throws Exception {
		// TODO 自动生成的方法存根
		// 1、收集参数、验证参数
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		 
		log.info("登陆的用户名："+username);
		log.info("登陆的密码："+password);
		user.setName(username);
		user.setPassWord(password);
		user.setID("11");
	 loginService.loginS(user);
	 
		Map<String, User> map = new HashMap<>();
		map.put("message", user);
		// 3、将命令对象传入业务对象进行业务处理
		// 4、选择下一个页面
		ModelAndView mv = new ModelAndView();
		// 添加模型数据 可以是任意的POJO对象

		mv.addAllObjects(map);

		// 设置逻辑视图名，视图解析器会根据该名字解析到具体的视图页面
		mv.setViewName("hello");
		return mv;

	}

 

}
